package com.dkm.biz.ou.repository.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.biz.ou.domain.Party;
import com.dkm.biz.ou.repository.PartyRepository;
import com.dkm.biz.ou.persistence.dao.PartyQueryDao;
import com.dkm.biz.ou.persistence.entity.PartyPo;

/**
 * 对象功能:t_ou_party Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2016-12-06 18:53:06
 */
@Repository
public class PartyRepositoryImpl extends AbstractRepository<String, PartyPo,Party> implements PartyRepository{
	  
	@Resource
	private  PartyQueryDao partyQueryDao;

	public Party newInstance() {
		PartyPo po = new PartyPo();
		Party party = SpringHelper.getBean(Party.class);
		party.setData(po);
		return party;
	}

	public Party newInstance(PartyPo po) {
		Party party = SpringHelper.getBean(Party.class);
		party.setData(po);
		return party;
	} 
	
	@Override
	protected IQueryDao<String, PartyPo> getQueryDao() {
		return partyQueryDao;
	}

	@Override
	public String findMaxLeaderNo() {
		Integer leaderNo = partyQueryDao.countByKey("findMaxLeaderNo", null);
		if(leaderNo ==null){
			leaderNo = 0;
		}
	    return getNextCode(leaderNo+1);
	}
	public  String getNextCode(Integer groupCode){
		String in = groupCode+"";
		int j = in.length();
		StringBuffer buffer = new StringBuffer();
		for(;j < 8;j++){
			buffer.append("0");
		}
		return buffer.toString()+groupCode;
	}
}
